<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#assign css>
    <style>
    </style>
</#assign>
<#assign js>
    <script>
        function del(id) {
            layer.confirm('确定删除吗?', {icon: 3, title: '提示'}, function (index) {
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: "/agent/delete/" + id,
                    success: function (res) {
                        layer.msg(res.message, {time: 2000}, function () {
                            location.reload();
                        });
                    }
                });
            });
        }

        function resetPassword(id) {
            layer.confirm('确定重置吗（默认密码：123456）?', {icon: 3, title: '提示'}, function (index) {
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: "/agent/resetPassword/" + id,
                    success: function (res) {
                        layer.msg(res.message, {time: 2000}, function () {
                            location.reload();
                        });
                    }
                });
            });
        }

        function closeAgent(id) {
            layer.confirm('确定关闭吗?', {icon: 3, title: '提示'}, function (index) {
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: "/agent/closeAgent/" + id,
                    success: function (res) {
                        layer.msg(res.message, {time: 2000}, function () {
                            location.reload();
                        });
                    }
                });
            });
        }

        function openAgent(id) {
            layer.confirm('确定开通吗?', {icon: 3, title: '提示'}, function (index) {
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: "/agent/openAgent/" + id,
                    success: function (res) {
                        layer.msg(res.message, {time: 2000}, function () {
                            location.reload();
                        });
                    }
                });
            });
        }

        //tableId,queryId,conditionContainer
        //var userTable;
        var winId = "userWin";
        $(function () {
            //init table and fill data
            //userTable = new CommonTable("user_table", "user_list", "searchDiv");

            //button event
            $('button[data-btn-type]').click(function () {
                var action = $(this).attr('data-btn-type');
                var rowId = "ceshi";
                switch (action) {
                    case 'add':
                        modals.openWin({
                            winId: winId,
                            title: '新增分站管理',
                            width: '900px',
                            url: "/agent/edit/ceshi"
                        });
                        break;
                    case 'edit':
                        if (!rowId) {
                            modals.info('请选择要编辑的行');
                            return false;
                        }
                        modals.openWin({
                            winId: winId,
                            title: '编辑分站管理【' + userTable.getSelectedRowData().name + '】',
                            width: '900px',
                            url: "/agent/edit/" + rowId,
                        });
                        break;
                    case 'delete':
                        if (!rowId) {
                            modals.info('请选择要删除的行');
                            return false;
                        }
                        modals.confirm("是否要删除该行数据？", function () {
                            ajaxPost(basePath + "/agent/delete/" + rowId, null, function (data) {
                                if (data.success) {
                                    //modals.correct("已删除该数据");
                                    userTable.reloadRowData();
                                } else {
                                    modals.error("分站管理数据被引用，不可删除！");
                                }
                            });
                        })
                        break;
                }

            });
            //form_init();
        });
    </script>
</#assign>
<@layout title="分站管理" active="agent">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            分站列表
        </h1>
        <ol class="breadcrumb">
            <li><a href="/"><i class="fa fa-home"></i> 管理后台</a></li>
            <li><a href="/agent/index"><i class="fa fa-list-ul"></i> 分站管理</a></li>
            <li class="active"><i class="fa fa-table"></i> 分站列表</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <!-- Default box -->
        <div class="box box-primary">
            <div class="box-header">
                <form class="form-horizontal form-edit" method="post" action="/agent/index" id="searchForm">
                    <div class="form-group" style="margin-top:10px;">
                        <div class="col-sm-2">
                            <input placeholder="请输入分站名称" id="name" name="name" class="form-control" type="text"
                                   value="${searchAgent.name!}">
                        </div>
                        <div class="col-sm-2">
                            <input placeholder="请输入分站ID" id="id" name="id" class="form-control" type="text"
                                   value="${searchAgent.id!}">
                        </div>
                        <div class="col-sm-2">
                            <input placeholder="请输入联系人" id="contact" name="contact" class="form-control" type="text"
                                   value="${searchAgent.contact!}">
                        </div>
                        <div class="col-sm-2">
                            <input placeholder="请输入联系人手机号" id="phone" name="phone" class="form-control" type="text"
                                   value="${searchAgent.phone!}">
                        </div>
                        <div class="col-sm-2">
                            <select name="stat" class="form-control">
                                <option value="0" <#if searchAgent.stat == 0>selected="selected"</#if>>已开通</option>
                                <option value="1" <#if searchAgent.stat == 1>selected="selected"</#if>>未开通</option>
                            </select>
                        </div>
                        <div class="btn-group">
                            <button type="submit" class="btn btn-primary" data-btn-type="search">查询</button>
                            <button type="button" class="btn btn-default" data-btn-type="reset"
                                    onclick="javascript:$('#searchForm')[0].reset()">重置
                            </button>
                        </div>
                    </div>
                </form>
                <#--<@shiro.hasPermission name="system:user:add">
                    <a class="btn btn-sm btn-success" href="/user/add">新增</a>
                </@shiro.hasPermission>-->
            </div>
            <div class="box-body">
                <table class="table table-striped">
                    <tr>
                        <th>分站id</th>
                        <th>区县名称</th>
                        <th>分站联系人</th>
                        <th>联系人手机号</th>
                        <th>开通时间</th>
                        <th>状态</th>
                        <th>开通人</th>
                        <th>奖励金额</th>
                        <th>取消订单扣款比例</th>
                        <th>操作</th>
                    </tr>
                    <#list pageInfo.list as item>
                        <tr>
                            <td>${item.id!}</td>
                            <td>${item.name!}</td>
                            <td>${item.contact!}</td>
                            <td>${item.phone!}</td>
                            <td>${(item.openAt?string('yyyy-MM-dd HH:mm:ss'))!}</td>
                            <td>${convert('AGENT_STATUS', item.stat)!}</td>
                            <td>${item.openBy!}</td>
                            <td>
                                <#if item.award?? >
                                    ${item.award?string('0.00')}
                                </#if>
                            </td>
                            <td>${item.cancelOrder!}%</td>
                            <td>
                                <@shiro.hasPermission name="system:agent:data">
                                    <a class="btn btn-sm btn-info" href="/agent/agentOrder?agentId=${item.id}&startTime=${startTime!}&endTime=${endTime!}"
                                       data-btn-type="detail">数据</a>
                                </@shiro.hasPermission>
                                <@shiro.hasPermission name="system:agent:detail">
                                    <a class="btn btn-sm btn-success" href="/agent/detail/${item.id}"
                                       data-btn-type="detail">详情</a>
                                </@shiro.hasPermission>
                                <@shiro.hasPermission name="system:agent:edit">
                                    <a class="btn btn-sm btn-primary" href="/agent/edit/${item.id}"
                                       data-btn-type="edit">编辑</a>
                                </@shiro.hasPermission>
                                <#if item.stat == 0>
                                    <@shiro.hasPermission name="system:agent:resetPassword">
                                        <button class="btn btn-sm btn-primary" onclick="resetPassword('${item.id}')"
                                           data-btn-type="edit">重置密码</button>
                                    </@shiro.hasPermission>
                                    <@shiro.hasPermission name="system:agent:closeAgent">
                                        <button class="btn btn-sm btn-danger" onclick="closeAgent('${item.id}')"
                                                data-btn-type="edit">关闭分站
                                        </button>
                                    </@shiro.hasPermission>
                                <#else >
                                    <@shiro.hasPermission name="system:agent:openAgent">
                                        <a class="btn btn-sm btn-primary" href="/agent/openAgent/${item.id}"
                                                data-btn-type="edit">开通分站
                                        </a>
                                    </@shiro.hasPermission>
                                </#if>

                                <#--<@shiro.hasPermission name="system:agent:delete">
                                    <button class="btn btn-sm btn-danger" onclick="del('${item.id}')">删除</button>
                                </@shiro.hasPermission>-->
                            </td>
                        </tr>
                    </#list>
                </table>
            </div>
            <!-- /.box-body -->
            <div class="box-footer clearfix">
                <@macro.page pageInfo=pageInfo url="/agent/index?name=${searchAgent.name!}&id=${searchAgent.id!}&contact=${searchAgent.contact!}&phone=${searchAgent.phone!}&stat=${searchAgent.stat!}" />
            </div>
        </div>
        <!-- /.box -->

    </section>
    <!-- /.content -->
</@layout>
